package com.baizhi.cmfz.aspect;

/**
 * @Configuration 表示这是一个配置类
 * @Aspect 表示这是一个增强类
 */

/*@Configuration
@Aspect
public class LogEnhanceTwo {

	private Logger logger = LoggerFactory.getLogger(LogEnhanceTwo.class);
	@Resource
	private CmfzLogDao cmfzLogDao;

	@After("@annotation(com.baizhi.cmfz.annotation.LogAnnotation)")
	public void testAfter(JoinPoint joinPoint){
		CmfzLog cmfzLog = new CmfzLog();
//		1.获取当前的时间
		Date date = new Date();
		cmfzLog.setLogDate(date);
//		2.获取session作用域,拿到admin对象，将对象的id赋值给cmfzlog
		ServletRequestAttributes requestAttributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
		HttpServletRequest request = requestAttributes.getRequest();
		HttpSession session = request.getSession();
		Admin admin = (Admin) session.getAttribute("admin");
		cmfzLog.setAdminId(admin.getAdminId());
		logger.debug("操作的管理员的id是"+admin.getAdminId());
//		3.获取本次访问的ip
		String ipAdrress = IpAddrressUtil.getIpAdrress(request);
		cmfzLog.setLogIp(ipAdrress);
//		4.获取操作的方法的对象
		MethodSignature signature = (MethodSignature) joinPoint.getSignature();
		Method method = signature.getMethod();
//		5.获取方法上的注解
		LogAnnotation annotation = method.getAnnotation(LogAnnotation.class);
//		6.获取type和value的值
		String type = annotation.type();
		String value = annotation.value();
		cmfzLog.setLogContent(value);
		cmfzLog.setLogType(type);

//		7.将对象添加到数据库

		cmfzLogDao.insertCmfzLog(cmfzLog);
	}

}*/


public class LogEnhanceTwo {}
